package engine.systems.control.cameraZoom
{
	import engine.classes.enumerations.SystemPriority;
	import engine.systems.update.GameSystem;
	import engine.utils.Key;
	
	public class CameraZoomSystem extends GameSystem
	{
		public function CameraZoomSystem()
		{
			super(CameraZoomNode, updateNode);
			
			this.priority = SystemPriority.UPDATE;
		}
		
		private function updateNode(node:CameraZoomNode, time:Number):void
		{
			if(node.zoom.locked) return;
		
			if(Key.isDown(node.zoom.zoomOut))
			{
				node.spatial.scaleX -= node.zoom.rate * time;
				node.spatial.scaleY -= node.zoom.rate * time;
				
				if(node.spatial.scaleX < node.zoom.minScale || node.spatial.scaleY < node.zoom.minScale)
				{
					node.spatial.scaleX = node.zoom.minScale;
					node.spatial.scaleY = node.zoom.minScale;
				}
			}
			
			if(Key.isDown(node.zoom.zoomIn))
			{
				node.spatial.scaleX += node.zoom.rate * time;
				node.spatial.scaleY += node.zoom.rate * time;
				
				if(node.spatial.scaleX > node.zoom.maxScale || node.spatial.scaleY > node.zoom.maxScale)
				{
					node.spatial.scaleX = node.zoom.maxScale;
					node.spatial.scaleY = node.zoom.maxScale;
				}
			}
		}
	}
}